package javaTec.StringIntern;

import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by yangshunxing on 2017/9/6.
 */
public class StringIntern {

    private static final int MAX = 40000000;
    private static final String[] DB_DATA = {"one","two","three","four","five","six","seven","eight","nine","zero"};

    public static void main(String[] args) throws Exception {
        long t = System.currentTimeMillis();
        String[] arr = new String[MAX];
        for (int i = 0; i < MAX; i++) {
//            arr[i] = new String(DB_DATA[i % 10]);
             arr[i] = new String(DB_DATA[i % 10]).intern();
        }
        long t1 = System.currentTimeMillis()-t;
        System.out.println("运行时间："+t1+ "ms");
        System.gc();
        long t2 = System.currentTimeMillis()-t;
        System.out.println("垃圾回收时间："+t2+"ms");
        System.out.println(arr[0]);

    }
}
